package com.machineapps.framework.util;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class Player {
	private static MediaPlayer mp = null;

	/** Stop old song and start new one */
	public static void play(Context context, int resource) {
		play(context, resource, null);
	}

	/** Stop old song and start new one */
	public static void play(Context context, int resource, OnCompletionListener onCompletionListener) {
		stop();

		mp = MediaPlayer.create(context, resource);
		mp.start();
		
		if(onCompletionListener != null){
			mp.setOnCompletionListener(onCompletionListener);
		}
	}

	/** Stop the music */
	public static void stop() {
		if (mp != null) {
			mp.stop();
			mp.release();
			mp = null;
		}
	}
}